package cn.tedu.basic;
//售票
public class Test6 {
    public static void main(String[] args) {
        A a =new A();
        A a1 =new A();
        A a2 =new A();
        a.start();
        a1.start();
        a2.start();
    }
}
class A extends Thread{
   static int sum =100;
    @Override
    public void run() {
        while (true) {
            synchronized (Thread.class) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (sum > 0) {
                    System.out.println(Thread.currentThread().getName() + "==" + sum--);
                } else {
                    break;
                }
            }
        }
    }
}
class B implements Runnable{
    int sum =100;
    @Override
    synchronized public void run() {
        while (true){
            if(sum>0){
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"=="+sum--);
            }else{
                break;
            }
        }
    }
}
class D implements Runnable{
    int sum =100;
    @Override
    public void run() {
        while (true){
            synchronized (this) {
                if (sum > 0) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + "==" + sum--);
                } else {
                    break;
                }
            }
        }
    }
}